<template>
  <li
    :class="{ active: isItem }"
    @mouseenter="isItem = true"
    @mouseleave="isItem = false"
  >
    <label>
      <input type="checkbox" :checked="comment" @change="checkedtodos(index)" />
      <span> {{ title }} </span>
    </label>
    <button class="btn btn-danger" @click="deleteTodo(index)">删除</button>
  </li>
</template>

<script lang="ts">
import { defineComponent, ref } from "vue";

export default defineComponent({
  name: "Item",
});
</script>

<script setup lang="ts">
defineProps<{
  id: string;
  title: string;
  comment: boolean;
  index: number;
  checkedtodos: Function;
  deleteTodo:Function;
}>();

// const emit = defineEmits<{
//   (event: "checkedtodos", index: number): void;
// }>();

const isItem = ref(false);
</script>

<style scoped>
/*item*/
li {
  list-style: none;
  height: 36px;
  line-height: 36px;
  padding: 0 5px;
  border-bottom: 1px solid #ddd;
}

li.active {
  background: green;
}
li.active .btn {
  display: block;
}

li label {
  float: left;
  cursor: pointer;
}

li label li input {
  vertical-align: middle;
  margin-right: 6px;
  position: relative;
  top: -1px;
}

li button {
  float: right;
  display: none;
  margin-top: 3px;
}

li:before {
  content: initial;
}

li:last-child {
  border-bottom: none;
}
</style>
